import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:smart_translator/app/event/DataCallBack.dart';
import 'package:smart_translator/app/modules/photoTranslate/controllers/photo_translate_controller.dart';
import '../../../style/app_colors.dart';
import '../../../style/widget_style.dart';
import '../../../widgets/AppHeader.dart';
import '../../../widgets/AudioWaveform.dart';
import '../../../widgets/CommonWidgets.dart';
import '../controllers/listener_translation_controller.dart';

class ListenerTranslationView extends GetView<ListenerTranslationController> {
  const ListenerTranslationView({super.key});

  @override
  Widget build(BuildContext context) {
    return SafeArea(child: Scaffold(
      body: SingleChildScrollView(
        child: Stack(
          children: [
            Container(
              child: SvgPicture.asset(
                "assets/images/header_part_bg.svg",
                width: Get.width,
              ),
            ),
            AppHeader.obtainHeaderForListenTranslation(DataCallBack(
              confirmCallBack: (v) {
                controller.showAudioLogsPoupWindow(context);
              },
              businessCallBack: (v) {
                controller.quite();
              }
            )),
            Obx(()=>Column(
              children: [
                controller.listenerContentType.value == 2 ?
                Container(
                  width: Get.width,
                  margin: EdgeInsets.only(top: 70.h),
                  padding: EdgeInsets.all(20.w),
                  child: Column(
                    children: [
                      Container(
                        width: Get.width,
                        height: 278.h,
                        decoration: BoxDecoration(

                          color:  Colors.white,
                          borderRadius: BorderRadius.only(topLeft: Radius.circular(8),topRight: Radius.circular(8)), // Optional: add border radius
                        ),
                        child: Stack(
                          children: [
                            controller.audioService.finalFromLanguage.value == '' ? Container(
                              child: Center(
                                child: Column(
                                  children: [
                                    SizedBox(height: 80.h,),
                                    Image.asset('assets/images/empty_list_realtime.png',width: 169.w,height: 91.h),
                                    SizedBox(height: 16.h,),
                                    Text('点击下方开始键开始同声翻译',style: AppStyleThemeData.HINT_TEXT_STYLE_small,)

                                  ],
                                ),
                              ),
                            ): Container(
                              padding: EdgeInsets.only(top: 45.h,left: 20.w,right: 20.w),
                              child: SingleChildScrollView(
                                controller: controller.fromControllerTopRegion,
                                child: Text(controller.audioService.finalToLanguage.value,style: TextStyle(
                                    color: AppColors.big_title_color,
                                    fontSize: controller.fontSize.value.sp
                                )),
                              ),
                            ),
                            Positioned(
                              child: Text('${controller.audioService.toLanFlagDisplay.value}',style: AppStyleThemeData.HINT_TEXT_STYLE_small),
                              left: 15.w,
                              top: 15.h,
                            )
                          ],
                        ),
                      ),
                      Container(
                        width: Get.width,
                        decoration: BoxDecoration(
                            color:  Colors.white // Optional: add border radius
                        ),//声波纹.
                        child: Column(
                          children: [
                            Row(
                              children: [
                                Image.asset('assets/images/icon_video_wave_sideline.png',width: 13.w,height: 13.h,),
                                Expanded(child: CommonWidgets.getMyDivider()),
                                controller.audioService.isPlaying.value ?
                                AudioWaveform(
                                  amplitudes: controller.amplitudes.value,
                                  height: 24.h,
                                  width: MediaQuery.of(context).size.width * 0.5,
                                  waveColor: controller.audioService.isPlaying.value ? Colors.blue : Colors.grey,
                                ):Image.asset('assets/images/icon_audio_wave_realtime.png',width: 176.w,height: 24.h),
                                Expanded(child: CommonWidgets.getMyDivider()),
                                Image.asset('assets/images/icon_video_wave_sideline.png',width: 13.w,height: 13.h,),

                              ],
                            )

                          ],
                        ),
                      ),
                      Container(
                        width: Get.width,
                        height: 300.h,
                        decoration: BoxDecoration(
                          color:  Colors.white,
                          borderRadius: BorderRadius.only(bottomLeft: Radius.circular(8),bottomRight: Radius.circular(8)), // Optional: add border radius
                        ),
                        child: Stack(
                          children: [
                            controller.audioService.finalToLanguage.value == ''? Container(
                              child: Center(
                                child: Column(
                                  children: [
                                    SizedBox(height: 80.h,),
                                    Image.asset('assets/images/empty_list_realtime.png',width: 169.w,height: 91.h),
                                    SizedBox(height: 16.h,),
                                    Text('点击下方开始键开始同声翻译',style: AppStyleThemeData.HINT_TEXT_STYLE_small,)

                                  ],
                                ),
                              ),
                            ): Container(
                              padding: EdgeInsets.only(top: 45.h,left: 20.w,right: 20.w,bottom: 50.h),
                              child: SingleChildScrollView(
                                controller: controller.toControllerBottomRegion,
                                child: Text(controller.audioService.finalFromLanguage.value,style: TextStyle(
                                    color: AppColors.big_title_color,
                                    fontSize: controller.fontSize.value.sp
                                )),
                              ),
                            ),
                            Positioned(
                              child: Text('${controller.audioService.fromLanFlagDisplay.value}',style: AppStyleThemeData.HINT_TEXT_STYLE_small),
                              left: 15.w,
                              top: 15.h,
                            )

                          ],
                        ),
                      )
                    ],
                  ),
                ) :
                Container(
                  width: Get.width,
                  margin: EdgeInsets.only(top: 75.h),
                  padding: EdgeInsets.only(left: 20.w,right: 20.w,top: 20.h),
                  child: Column(
                    children: [
                      Container(
                        width: Get.width,
                        height: Get.height-215.h,
                        margin: EdgeInsets.only(bottom: 20.h),
                        decoration: BoxDecoration(
                          boxShadow: [
                            CommonWidgets.getBoxShadow(),
                          ],
                          color: Colors.white,
                          borderRadius: BorderRadius.only(topLeft: Radius.circular(8),topRight: Radius.circular(8)), // Optional: add border radius
                        ),
                        child: Container(
                          padding: EdgeInsets.only(left: 20.w,right: 20.w,top: 20.h,bottom: 120.w),
                          child: (controller.listenerContentType.value == 1 && controller.audioService.finalToLanguage.value != '') ? SingleChildScrollView(
                              controller: controller.fromController,
                              child: Text(controller.audioService.finalToLanguage.value,style: TextStyle(
                                  color: AppColors.big_title_color,
                                  fontSize: controller.fontSize.value.sp
                              ),)) :
                          (controller.listenerContentType.value == 0 && controller.audioService.finalFromLanguage.value != '') ? SingleChildScrollView(
                              controller: controller.fromController,
                              child: Text(controller.audioService.finalFromLanguage.value,style: TextStyle(
                                  color: AppColors.big_title_color,
                                  fontSize: controller.fontSize.value.sp
                              ),)):
                          Center(
                            child: Column(
                              children: [
                                SizedBox(height: 80.h,),
                                Image.asset('assets/images/empty_list_realtime.png',width: 169.w,height: 91.h),
                                SizedBox(height: 16.h,),
                                Text('点击下方开始键开始听译',style: AppStyleThemeData.HINT_TEXT_STYLE_small,)

                              ],
                            ),
                          ),
                        ),
                      ),

                    ],
                  ),
                ),
                Container(
                  color: Colors.white,
                  width: Get.width,
                  padding: EdgeInsets.only(bottom: 16.h,left: 10.w,right: 10.w,top: 14.h),
                  child: Row(
                    mainAxisAlignment:  MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () {
                          controller.showLanguagePoupWindow(context);
                        },
                        child: Container(
                          padding: EdgeInsets.only(top:8.h,bottom:5.h),
                          child: Column(
                            children: [
                              Obx(()=>Text('${controller.audioService.fromLanFlagDisplay.value.substring(0,1) + '-' +
                                  controller.audioService.toLanFlagDisplay.value.substring(0,1)}',style: AppStyleThemeData.listener_bottom_label_value)),
                              Text('语言设置',style: AppStyleThemeData.normal_bold_small,)
                            ],
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          controller.showFontPoupWindow(context);
                        },
                        child: Container(
                          padding: EdgeInsets.only(top:8.h,bottom: 8.h),
                          child: Column(
                            children: [
                              Text('${controller.fontDisplay.value}',style: AppStyleThemeData.listener_bottom_label_value),
                              Text('字体大小',style: AppStyleThemeData.normal_bold_small,)
                            ],
                          ),
                        ),
                      ),
                      Container(
                        child: InkWell(
                          onTap: () {
                              controller.playOrPause();
                          },
                          child: controller.audioService.isPlaying.value ? Image.asset('assets/images/icon_play_realtime_btn_running.png',width: 55.w,height: 55.h):
                          Image.asset('assets/images/icon_play_realtime_btn.png',width: 55.w,height: 55.h),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          controller.showFloatingWindow(context);
                        },
                        child: Container(
                          padding: EdgeInsets.only(top:8.h,bottom: 8.h),

                          child: Column(
                            children: [
                              Image.asset('assets/images/icon_double_languages.png',width: 24.w,height: 24.h),
                              Text('浮窗显示',style: AppStyleThemeData.normal_bold_small,)
                            ],
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          controller.showDoubleLanguage();
                        },
                        child: Container(
                          padding: EdgeInsets.only(top:8.h,bottom: 8.h),
                          child: Column(
                            children: [
                              controller.listenerContentType.value == 0 ? Container(
                                child: Image.asset('assets/images/icon_listener_interchanges_fromlanguage.png',width: 24.w,height: 24.h),
                                width: 25.w,
                                height: 25.h,
                              ):
                              controller.listenerContentType.value == 1 ? Container(
                                child: Image.asset('assets/images/icon_listener_interchanges_tolanguage.png',width: 24.w,height: 24.h),
                                width: 25.w,
                                height: 25.h,
                              ):
                              Container(
                                child: Image.asset('assets/images/icon_float_windows_show.png',width: 24.w,height: 24.h),
                                width: 25.w,
                                height: 25.h,
                              ),
                              controller.listenerContentType.value == 0 ? Text('显示原文',style: AppStyleThemeData.normal_bold_small,):
                              controller.listenerContentType.value == 1 ? Text('显示译文',style: AppStyleThemeData.normal_bold_small,):
                              Text('双语对照',style: AppStyleThemeData.normal_bold_small,)
                            ],
                          ),
                        ),
                      )

                    ],
                  ),
                )
              ],
            ))
          ],
        ),
      ),
    ),top: false);
  }

}
